<template>
    <ElTable :data="tableData" :max-height="tableHeight" class="my-table">
        <ElTableColumn label="行业" prop="category"></ElTableColumn>
        <ElTableColumn label="品类名称"  prop="type"></ElTableColumn>
        <ElTableColumn label="产品名称中文" prop="name"></ElTableColumn>
        <ElTableColumn label="提交时间" prop="submitTime" ></ElTableColumn>
        <ElTableColumn label="审核状态" prop="status"></ElTableColumn>
        <ElTableColumn label="操作" width="120">
            <template #default="{ row }">
                <ElButton type="primary" link @click="handleView(row.id)">查看</ElButton>
            </template>
        </ElTableColumn>
    </ElTable>
</template>


<script setup lang="ts">
import router from '@/router'

interface Params {
    current: number;
    size: number;
    sortField: string;
    sortOrder: string;
    type: string;
    status: string;
}

const params = ref<Params>({
    current: 1,
    size: 10,
    sortField: '',
    sortOrder: '',
    type: '',
    status: ''
});

const tableData = ref<any[]>([]);
const tableHeight = ref(400);

const getData = async (data?: Partial<Params>): Promise<number> => {
    try {
        if (data) {
            params.value = { ...params.value, ...data };
        }
        const res:any = await MyService.resource.getProductReviewList(params.value);
        if (res.code == 200) {
            tableData.value = res.data.records;
            return res.data.total;
        } else {
            return 0;
        }
    } catch (error) {
        return 0;
    }
};

const handleView = (id: string) => {
    router.push({ name: 'productDetail', query: { id } });
};

defineExpose({
    refresh: getData,
});

onBeforeMount(() => {
    tableHeight.value = document.body.scrollHeight - 256;
});
</script>

<style scoped></style>
